﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace DataAccessMock
{
    public class XmlHandler
    {
        public XmlDocument SearchXMLFile(string fileName)
        {
            XmlDocument xml = new XmlDocument();

            string[] files = System.IO.Directory.GetFiles(System.Threading.Thread.GetDomain().BaseDirectory + System.Configuration.ConfigurationSettings.AppSettings["DB2_MOCK_FOLDER"], "*.xml");

            string file = files.First(x => x.Contains(fileName));

            if (string.IsNullOrEmpty(file))
            {
                throw new Exception("Arquivo XML não encontrado");
            }
            else
            {
                xml.Load(file);
            }

            return xml;
        }
    }
}
